package MultiPong;

import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;

public class HoofdPaneel extends JPanel {
	private static final long serialVersionUID = 1L;	
	
	private JButton ClientKnop = new JButton("Start Client");
	private JTextField IPVak = new JTextField("localhost");
	private Server server = new Server();
	private Client client;
	int startaantal = 0;
	
	private static HoofdPaneel instance;

	public static HoofdPaneel getInstance() {
		if (instance == null) {
			instance = new HoofdPaneel();
		}
		return instance;
	}
	
	public HoofdPaneel() {
		this.setLayout(null);
		this.setBorder(BorderFactory.createTitledBorder("De controleknoppen"));
		
		ClientKnop.addActionListener( new ClientHandler());
		ClientKnop.setBounds(50,80,110,27);
		this.add(ClientKnop);
		
		IPVak.setBounds(50,110,110,27);
		this.add(IPVak);
		
		try {
			JLabel mijnIP = new JLabel("Eigen IP: "+InetAddress.getLocalHost().getHostAddress());
			mijnIP.setBounds(7,775,200,27);
			this.add(mijnIP);
		} catch(Exception e) {
			e.printStackTrace();
		}

			server.start();

		
		
	}
	
	public String getXpos(){
		String xpos = server.getXpos();
		return xpos;
	}
	public String getXpos_bal(){
		String xpos_bal = server.getXpos_bal();
		return xpos_bal;
	}
	public String getYpos_bal(){
		String ypos_bal = server.getYpos_bal();
		return ypos_bal;
	}
	
	class ClientHandler implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent e) {

			client = new Client(IPVak.getText());
			client.start();
	        
		}
	
			
	}
		
}
	

